import 'package:flutter/material.dart';
import 'MyIcon.dart';
import 'pages/BusPage.dart';
import 'pages/MinePage.dart';
import 'pages/ShoppingPage.dart';
import 'pages/PlanePage.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button',
      /*theme: ThemeData(
        primarySwatch: Colors.blue,
      ),*/
      home: MyStateWidget(),
    );
  }
}

class MyStateWidget extends StatefulWidget{
  @override
  _MyStateWidget createState() => _MyStateWidget();
}

class _MyStateWidget extends State<MyStateWidget>{

  int currentIndex = 0;

  List pageList = [
    BusPage(),
    PlanePage(),
    ShoppingPage(),
    MinePage()
  ];

  GlobalKey<ScaffoldState> _globalKey = new GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _globalKey,
      //顶部导航栏
      appBar: AppBar(
        title: Text("第一个标题"),
        leading: IconButton(icon: Icon(Icons.dashboard),onPressed: (){
          _globalKey.currentState.openDrawer();
        },),
        actions: <Widget>[
          IconButton(icon: Icon(MyIcon.xiaomi),onPressed: (){print("小米");},)
        ],
      ),
      drawer: Container(
        width: 300,
        color: Colors.pink,
        child: Column(
          children: <Widget>[
            Text("抽屉内容区域")
          ],
        ),
      ),
      //页面
      body: this.pageList[this.currentIndex],
      //底部导航栏
      bottomNavigationBar: BottomNavigationBar(
        //超过四个必须加这个属性
        type: BottomNavigationBarType.fixed,
        items:<BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.airport_shuttle),title: Text("bus")),
          BottomNavigationBarItem(icon: Icon(Icons.airplanemode_active),title: Text("air")),
          BottomNavigationBarItem(icon: Icon(Icons.shopping_cart),title: Text("shopping")),
          BottomNavigationBarItem(icon: Icon(Icons.person),title: Text("mine")),

        ],
        currentIndex: this.currentIndex,
        onTap: (index){
          setState(() {
            this.currentIndex = index;
          });
        },
      ),
      //悬浮按钮
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: (){
          print("checked");
        },
      ),
    );
  }

}